package us.gaaoc.framework.webapp.backingbeans.viewOnly;


import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;

import us.gaaoc.framework.businessmodel.Filing;
import us.gaaoc.framework.webapp.backingbeans.BaseBackingBean;

/**
 * @author tapshals
 *
 */
@SuppressWarnings("unchecked")
public class NewFilingPage extends BaseBackingBean{
	
	/**
	 * Properties
	 */
	
	/** Generated Serial Version UID */
	private static final long serialVersionUID = -8002233915902306384L;
	
	private DataModel dataTableList;
	
	/**
	 * Constructor
	 *
	 */
	public NewFilingPage(){
		dataTableList = new ListDataModel();
		this.loadData();
	}


	/**
	 * @return Returns the dataTableList.
	 */
	public DataModel getDataTableList() {
		return dataTableList;
	}

	/**
	 * @param dataTableList The dataTableList to set.
	 */
	public void setDataTableList(DataModel dataTableList) {
		this.dataTableList = dataTableList;
	}

	/**
	 * This method loads the data from the database of status="Received"
	 *
	 */
	private void loadData(){
        //   status = received (1)
		String courtUuid = (String) FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("courtUuid");
		List<Filing> newFilings = this.getModelFacade().findCaseFilingsByStatus(1, courtUuid);			
		dataTableList.setWrappedData(newFilings);
	}

	/**
	 * This method navigates user to the Case Details Page
	 * @return String
	 */
	public String gotoCaseDetailPage(){
		Map sessionMap = this.getFacesContext().getExternalContext().getSessionMap();
	 	Map requestMap = this.getFacesContext().getExternalContext().getRequestParameterMap();
	 	String caseUuid = ((String) requestMap.get("caseUuid"));
	 	
	 	sessionMap.put("caseUuid", caseUuid);
	 	sessionMap.put("from", "publicNewFilingPage");
		
	 	return "caseDetailsPage";
	}
	
	/**
	 * This method navigtes user to the previous page
	 * @return String
	 */
	public String back(){
		return "back";
	}	
}
